//商品搜索页
function xinpinindexsearch() {
    let mockData = Mock.mock({
        "crumblist|4-6": [{
            "text": "@ctitle(4,18)",
            "href": "#"
        }],
        "prolist|8": [{
            'img': "@image('214x274',#eac7ce)",
            'title': "@ctitle(5, 10)",
            'sellprice|100-200.2': 239.00,
            'manjian|0-1': 0,
            'baoyou|0-1': 0
        }],
        "catelist|2": [{
            'name': "品牌",
            'list|15-30': ["@ctitle(2, 6)"]
        }]
    });
    new Vue({
        el: "#indexsearch",
        data() {
            return {
                params:'',//搜索框
                prolist: '', //商品数组
                type: 1,
                catelist: '', //分类数组
                crumblist: [],
                brandlist: '', //品牌数组
                url_params: urlParam.href(), //当前url参数
                titalCount: '', //总页数
                where: {
                    pages: 0,
                    brandId: '',
                    sortId: '',
                    keyword: '',
                    price: '',
                    minPrice: '',
                    maxPrice: '',
                    sales: '',
                    isNew:0,
                },
                topnavlist: {},
                pageNo:1
            }
        },
        methods: {
            getPaixu(type, minprice, maxpice) {
                if (type == 3) {
                    if(this.where.price.length==0){
                        this.where.price=0;
                    }else{
                        this.where.price=(this.where.price == 0) ? 1:0;
                    }
                    this.where.sales = '';
                } else if (type == 2) {
                    this.where.price = '';
                    this.where.sales = 1;
                } else {
                    this.where.price = '';
                    this.where.sales = '';
                }
                this.where.minPrice = minprice;
                this.where.maxPrice = maxpice;
                this.getList();
            },
            getData() {
                var that = this;
                if(that.url_params.keyword){
                    this.params=decodeURI(that.url_params.keyword);
                }

                //获取品牌分类
                /*axios({
                    method: 'post',
                    url: urlParam.domain() + '/api/brand/brandSort',
                    responseType: 'stream',
                }).then(function(response) {
                    that.brandlist = response.data.data;
                });*/
                //获取所有品牌
                axios({
                    method: 'get',
                    url: urlParam.domain() + '/api/brand/allBrand',
                    responseType: 'stream',
                }).then(function(response) {
                    that.brandlist = response.data.data;
                });

                if (that.url_params.sortId) {
                    //获取分类
                    axios({
                        method: 'get',
                        url: urlParam.domain() + '/api/category/categoryListByParentId?parentId=' + that.url_params.sortId,
                        responseType: 'stream',
                    }).then(function(response) {
                        that.catelist = response.data.data;
                    });
                }
                /*if (that.url_params.keyword) {
                    //判断是搜索商品还是店铺
                    axios({
                        method: 'get',
                        url: urlParam.domain() + '/api/productInfo/shopOrProduct?keyword=' + that.url_params.keyword,
                        responseType: 'stream',
                    }).then(function(response) {

                        //http://api.juyihome.com/dist/html/product/product_list.html?searchResult=1&keyword=1231
                    });
                }*/
                this.getList();
                this.crumblist = mockData.crumblist;
                //this.prolist = mockData.prolist;
                //this.catelist = mockData.catelist;
            },

            //获取商品列表数据
            getList() {
                var that = this;
                that.where.keyword=that.url_params.keyword==null?'':that.url_params.keyword;
                axios({
                    method: 'post',
                    url: urlParam.domain() + '/api/productInfo/productSearch',
                    responseType: 'stream',
                    params: this.where
                }).then(function(response) {
                    that.prolist = response.data.data.products;
                    that.titalCount =getPageCount(response.data.data.titalCount,10)
                });
            },

            //点击品牌
            brandClick: function(e) {
                this.where.brandId = e;
                this.getList();
            },
            //点击分类
            cateClick: function(e) {
                this.where.sortId = e;
                this.getList();
            },
            listen: function(data) {
                // 翻页事件
                this.pageNo=data;
                this.where.pages=data-1;
                this.getList();
                // alert('当前页码：' + data);
            }
        },
        created() {
            this.getData();
        },
        mounted() {

        },
        components: {
            'pro-list': base_product_list,
            //'cate-shaixuan': cate_shaixuan,
            'paixu': paixu,
        }
    });
}
